public class Student1 {
    //私有属性（只能在本类访问）
    String studentId; //学号
    String name; //学号
    private int age;
    private String major;
    private double score;
//    private String studentId; //学号
//    private String name;     //姓名

    //无参构造方法（默认存在,手动定义后需显式写出）
//    public Student(){
//        this.studentId = "未知";
//        this.name = "未知";
//    }
    //有参构造方法（初始化学号和姓名）
    public Student1(String studentId, String name, String major) {
        this.studentId = studentId;
        this.name = name;
        this.major = major;
    }

    //getter方法:获取属性值

    public String getStudentId() {
        return studentId;
    }

    //setter方法：设置属性值
    public void setStudentId(String studentId) {
        this.studentId = studentId;//this表示当前对象
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMajor() {
        return name;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    public double getScore() {
        return score;
    }


    public void setScore(double score) {
        if (score >= 0 && age <= 100) {
            this.score = score;
        } else {
            System.out.println("成绩不合法（必须0-100分）");
        }
    }

    //自定义方法：显示学生完整需显
    public void showInfo() {
        System.out.println("学号：" + studentId + ",姓名：" + name + ",专业:" + major + "成绩:" + score + "分");
    }

}

